package com.itheima.mq.rabbitmq.cluster;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;

/**
 * 测试Direct类型的交换机
 */
// @Component
public class RabbitmqDirectExchangeConfiguration {
    
    // 声明交换机
    @Bean(name = "direct.exchange")
    public Exchange directExchange() {
        return ExchangeBuilder.directExchange("direct.exchange").durable(true).build();
    }
    
    // 声明队列
    @Bean(name = "queue_test01")
    public Queue commonQueue01() {
        return QueueBuilder.durable("queue_test01").build();
    }
    
    // 完成队列和交换机的绑定
    @Bean
    public Binding directQueueBindToFanoutQueue01(
            @Qualifier(value = "direct.exchange") Exchange exchange,
            @Qualifier(value = "queue_test01") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with("cluster").noargs();
    }
    
}
